//
//  ApplyeOilHeadView.m
//  Base_App
//
//  Created by Yutian Duan on 2019/6/11.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "ApplyeOilHeadView.h"

@interface ApplyeOilHeadView() {
  NSArray *titleArray;
}

@property (nonatomic, strong) UIImageView *bgImageView;
@property (nonatomic, strong) UILabel *stepLabel;
@property (nonatomic, strong) UIImageView *stepImageView;
@property (nonatomic, strong) UIButton *personalButton;
@property (nonatomic, strong) UIButton *companyButton;

@end

@implementation ApplyeOilHeadView

- (instancetype)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    _isPersonal = YES;
    [self creatViews];
  }
  return self;
}

- (void)creatViews {
  
  titleArray = @[YTLocalizedString(@"申请资料"),YTLocalizedString(@"车轮资料"),YTLocalizedString(@"付款授权"),YTLocalizedString(@"附件上传"),@"申请完成"];
  
  _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth * ITEMPRO)];
  _bgImageView.contentMode = UIViewContentModeScaleAspectFill;
  _bgImageView.image = [UIImage imageNamed:@"Home_BgImage"];
  _bgImageView.clipsToBounds = YES;
  [self addSubview:_bgImageView];
  
  _stepLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, _bgImageView.yt_height/2 - 30, _bgImageView.yt_width - 80, 25)];
  _stepLabel.textColor = DEF_RED;
  _stepLabel.font = [UIFont systemFontOfSize:15.0f];
  _stepLabel.textAlignment = NSTextAlignmentCenter;
  _stepLabel.text = titleArray[0];
  [self addSubview:_stepLabel];
  
  CGFloat imageH = 3;
  _stepImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, _stepLabel.yt_bottom + 10, imageH * 50, imageH)];
  _stepImageView.image = [UIImage imageNamed:@"OilStep1"];
  _stepImageView.yt_centerX = _stepLabel.yt_centerX;
  [self addSubview:_stepImageView];
  
  //! 个人
  _personalButton = [[UIButton alloc] initWithFrame:CGRectMake(0, _stepImageView.yt_bottom + 10, 100, 30)];
  _personalButton.titleLabel.font = [UIFont systemFontOfSize:15.0f];
  [_personalButton setTitle:YTLocalizedString(@"个人") forState:UIControlStateNormal];
  [_personalButton setImage:[UIImage imageNamed:@"Oil_CheckImage_0"] forState:UIControlStateNormal];
  [_personalButton setImage:[UIImage imageNamed:@"Oil_CheckImage_1"] forState:UIControlStateSelected];
  [_personalButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  [_personalButton addTarget:self action:@selector(changeCLick:) forControlEvents:UIControlEventTouchUpInside];
  _personalButton.yt_right = self.yt_centerX - 5;
  [self addSubview:_personalButton];
  
  //! 公司
  _companyButton = [[UIButton alloc] initWithFrame:CGRectMake(0, _personalButton.yt_top, _personalButton.yt_width, _personalButton.yt_height)];
  _companyButton.titleLabel.font = [UIFont systemFontOfSize:15.0f];
  [_companyButton setTitle:YTLocalizedString(@"公司") forState:UIControlStateNormal];
  [_companyButton setImage:[UIImage imageNamed:@"Oil_CheckImage_0"] forState:UIControlStateNormal];
  [_companyButton setImage:[UIImage imageNamed:@"Oil_CheckImage_1"] forState:UIControlStateSelected];
  [_companyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  [_companyButton addTarget:self action:@selector(changeCLick:) forControlEvents:UIControlEventTouchUpInside];
  _companyButton.yt_left = self.yt_centerX + 5;
  [self addSubview:_companyButton];
  
  _personalButton.selected = YES;
  
}

- (void)setStepCount:(NSInteger)stepCount {
  _stepCount = stepCount;
  
  _stepImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"OilStep%zd",_stepCount+1]];
  _stepLabel.text = titleArray[_stepCount];

}

- (void)setIsPersonal:(BOOL)isPersonal {
  _isPersonal = isPersonal;
  if (_isPersonal == YES) {
    _personalButton.selected = YES;
  } else {
    _personalButton.selected = NO;
  }
  _companyButton.selected = !_personalButton.selected;

}


- (void)changeCLick:(UIButton *)sender {
  sender.selected = YES;
  if (sender == _personalButton) {
    if (_isPersonal == NO) {
      _isPersonal = YES;
      _companyButton.selected = NO;
      if (self.checkPersonal) {
        self.checkPersonal();
      }
    }
    
  } else {
    if (_isPersonal == YES) {
      _isPersonal = NO;
      _personalButton.selected = NO;
      if (self.checkPersonal) {
        self.checkPersonal();
      }
    }
    
  }
  
}

@end
